package com.filesys.core.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class IPUtils {

    public static List<String> getNetworkAddress() {
        List<String> result = new ArrayList<String>();
        Enumeration<NetworkInterface> netInterfaces = null;
        try {
            netInterfaces = NetworkInterface.getNetworkInterfaces();
        } catch (Exception e) {}
        if (netInterfaces != null) {
            InetAddress ip = null;
            while (netInterfaces.hasMoreElements()) {
                try {
                    NetworkInterface ni = netInterfaces.nextElement();
                    Enumeration<InetAddress> addresses = ni.getInetAddresses();
                    while (addresses.hasMoreElements()) {
                        ip = addresses.nextElement();
                        if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(':') == -1) {
                            result.add(ip.getHostAddress());
                        }
                    }
                } catch (Exception e) {}
            }
        }
        return result;
    }
}
